<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>推送</title>
    <link rel="stylesheet" type="text/css" href="../../css/aui2/aui.css"/>
    <style>
    	html,body{
    		height:100%;
    	}
    </style>
</head>
<body>
	<div class="aui-content aui-margin-b-15" id="push_list">
    </div>
    <script id="push_template" type="text/x-dot-template">
	    <ul class="aui-list aui-media-list">
	    	{{ for(var i=0;i<it.length;i++) { }}
			<li class="aui-list-item aui-list-item-middle" tapmode onclick="openCourses({{=it[i].id}})">
	            <div class="aui-media-list-item-inner">
	                <div class="aui-list-item-inner aui-list-item-arrow">
	                    <div class="aui-list-item-text">
	                        <div class="aui-list-item-title aui-font-size-14">{{=it[i].title}}</div>
	                    </div>
	                    <div class="aui-list-item-text">
	                    	<span>{{="推送老师"+it[i].teacher}}</span><span>{{=it[i].send_time}}</span>
	                    </div>
	                </div>
	            </div>
	        </li>
	        {{ } }}
	    </ul>
    </script>
</body>
<script src="../../script/doT.min.js"></script>
<script data-main="../../script/main" src="../../script/require.js"></script>
<script type="text/javascript">
	var token;
	var count=0;
	var isbottom = false;//是否到底
	var isRefresh = true;//是否刷新
	apiready = function(){
		require(["zepto","common"],function(){
			$zb.prefs.getPrefs('token',function(ret){
		    	token = ret.value;
		    	sendAjax();
		    })
		    
		    api.setRefreshHeaderInfo({
			    loadingImg: 'widget://image/refresh.png',
			    bgColor: '#ccc',
			    textColor: '#fff',
			    textDown: '下拉刷新...',
			    textUp: '松开刷新...'
			}, function(ret, err) {
				api.refreshHeaderLoadDone();
				if(ret){
				    isbottom = false;
                    isRefresh=true;
					sendAjax();
				}
			});
			
			api.addEventListener({
                name:'scrolltobottom',
                extra:{
                    threshold:0            //设置距离底部多少距离时触发，默认值为0，数字类型
                }
            }, function(){
                isRefresh = false;
                isbottom?api.toast({
                    msg:'没有更多了'
                }):sendAjax(count);        
            });
		})
	};
	
	function sendAjax(num){
		var data = {
			values:{
				token:token,
				appindex:num
			}
		}
		$zb.requestForData(data,'push','getPushCourses',function(ret){
		    if(ret&&ret.status==="OK"){
                if(ret.data.length>0){
                    
                    if(isRefresh){
                        $("#push_list").html(doT.template($("#push_template").text())(ret.data));
                    }else{
                        $("#push_list").append(doT.template($("#push_template").text())(ret.data));
                    }
                    if(ret.data.length===10){
                        count+=10;
                    }else{
                        isbottom = true;
                    }   
                }else{
                    $("#push_list").html("");
                }
		    }
		});
	}
	
	function openCourses(id){
		api.openWin({
	        name: 'push_courses',
	        url: './push_courses.html',
	        pageParam:{
	        	id:id
	        }
        });
	}
</script>
</html>